Skip to content

feat(hooks): add use hook#5126

Open
gaoachao wants to merge 1 commit into
preactjs:mainfrom
gaoachao:p/gcc/use-hook
Open

feat(hooks): add use hook#5126
gaoachao wants to merge 1 commit into
preactjs:mainfrom
gaoachao:p/gcc/use-hook

Conversation

@gaoachao

Copy link
Copy Markdown

Summary

  • add React 19-style use() support in preact/hooks for Promises and Contexts
  • keep use() order-insensitive by avoiding useState/useContext internally
  • expose use through compat default/types and add coverage for Promise, Context, conditional calls, falsy values, rejection, exports, and TS types

Tests

  • npm test

@github-actions

Copy link
Copy Markdown

📊 Tachometer Benchmark Results

Summary

A summary of the benchmark results will show here once they finish.

Results

The full results of your benchmarks will show here once they finish.

tachometer-reporter-action v2 for CI

@gaoachao gaoachao marked this pull request as ready for review June 29, 2026 08:18
@gaoachao

Copy link
Copy Markdown
Author

Hi @JoviDeCroock @rschristian , I reworked the use() implementation based on your feedback from #4970, especially around keeping it small, avoiding React-specific details in core, and not building it on top of order-sensitive hooks like useState or useContext.

The new PR implements use() for Promises and Contexts, with tests covering conditional calls, falsy promise values, rejection handling, shared promises, Context updates, exports, and TypeScript types. When you have time, could you take another look and let me know if this direction better matches Preact’s design philosophy?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant